#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "utils.h"
#include "graph.h"
#include "cluster.h"

#define FILE_PATH_SIZE 256
int main(int argc, char * argv[])
{	
	FILE* fEdge;
	FILE* fVertex;
	char outputFolder[FILE_PATH_SIZE];
	int ub, lb, k, status;
	int *vertexes_sol, *cluster_sizes;
	double * objvals, *x, objval;
	char *fPathEdge = (char *)malloc(sizeof(char)*FILE_PATH_SIZE);
	char *fPathVertex = (char *)malloc(sizeof(char)*FILE_PATH_SIZE);
	
	//TODO:CheckInput!!!!
	assert(argc == 5);

	strcpy(fPathEdge,argv[1]); 
	strcat(fPathEdge,"\\edges");
	
	strcpy(fPathVertex ,argv[1]); 
	strcat(fPathVertex ,"\\nodes");

	if(read_vertexes(fPathVertex) == 0)
		return 0;
	if (read_edges(fPathEdge) == 0)
		return 0;

	strcpy(outputFolder,argv[2]);
	lb = atoi(argv[3]);
    ub = atoi(argv[4]);
	objvals = (double*) calloc(ub-lb+1, sizeof(double));
	
	for (k = lb; k<=ub; k++)
	{
		status = k_cluster(k, &x, &objval);
		 if(status) {
            perror("Failed to solve problem");
            goto TERMINATE; 
        }

		 turn_solution_to_arrays(k, x, &vertexes_sol, &cluster_sizes);
		
	}

	print();


	TERMINATE:
    
    if (objvals != NULL)
    {
        free(objvals);
    }

	
	//TODO: Free
	return 1;
}